package cn.parus.dynamicRouter.mapper;

import cn.parus.dynamicRouter.entity.ApiInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ApiMapper {

    @Select("SELECT * FROM api_info")
    List<ApiInfo> getAll();

    @Select("SELECT * FROM api_info WHERE id = #{id}")
    ApiInfo getById(String id);

    @Select("SELECT * FROM api_info WHERE service_id = #{serviceId}")
    List<ApiInfo> getByServiceId(String serviceId);

    @Insert("INSERT INTO api_info (service_id, route_path, request_path) VALUES (#{serviceId}, #{routePath}, #{requestPath})")
    void insert(ApiInfo apiInfo);

    @Update("UPDATE api_info SET route_path = #{routePath}, request_path = #{requestPath} WHERE service_id = #{serviceId}")
    void update(ApiInfo apiInfo);

    @Delete("DELETE FROM api_info WHERE id = #{id}")
    void delete(String id);
}